<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/Negozio/templateNegozio.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:define name="pannello">

        <h:panelGrid columns="1">

            <p:growl id="msg" showDetail="false" autoUpdate="true"/> 

            #{gestioneNegozio.setRiassortimento(gestioneRiassortimento)}
            
            <h:form id="dimensioniTabelle" style="width: 100%">

                <p:dataGrid value="#{gestioneNegozio.prodottiInEsaurimento()}" var="f" columns="3" paginator="true" rows="9" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="9,12,15" style="width: 100%" emptyMessage="#{msg.prodottiInEsaurimentoNull}">

                    <f:facet name="header">

                        <h:outputText value="#{msg.prodInEsaurimentoTable}"/>
                    </f:facet>

                    <p:panel header="#{f.prodotto.nome}" style="width: 220px; height: 270px; text-align:center" footer="#{msg.quantitaRimanente} #{f.quantita}">  

                        <h:panelGrid columns="1">   

                            <p:graphicImage value="#{f.prodotto.foto.fotoPath()}" width="100px"/>
                            <p:commandLink value="#{msg.quantitaModifica}" action="#{gestioneRiassortimento.setRiassortimento(f.prodotto.marchio, f.prodotto)}"/>
                        </h:panelGrid>
                    </p:panel>
                </p:dataGrid>
            </h:form>

            <h:form id="ordini">

                <p:dataTable id="ordiniTabella" value="#{gestioneNegozio.ordiniInElaborazione()}" var="o" emptyMessage="#{msg.ordiniEmpty}" style="width: 100%; margin-top: 30px"> 

                    <f:facet name="header">

                        <h:outputText value="#{msg.nuoviOrdiniTable}"/>
                    </f:facet>

                    <p:column style="width:2%">  
                        <p:rowToggler />  
                    </p:column> 

                    <p:column style="width:30%" headerText="#{msg.numeroOrdineTable}" sortBy="#{o.cliente.cognome}">  

                        <h:outputText value="#{o.id}" />  
                    </p:column>  

                    <p:column style="width:50%" headerText="#{msg.clienteTable}" sortBy="#{o.cliente.cognome}">  

                        <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>

                    </p:column> 

                    <p:column style="width:20%" headerText="#{msg.totaleTable}">  

                        <h:outputText value="#{o.totale}" />  
                    </p:column> 

                    <p:rowExpansion>  

                        <p:panelGrid  columns="2" style="border: hidden">

                            <p:dataTable id="dettaglioOrdine" var="p" value="#{gestioneNegozio.ottieniProdottiDaOrdine(o.id)}" style="width: 280px">

                                <p:column headerText="#{msg.prodottoTable}" sortBy="#{p.prodotto.nome}">

                                    <h:outputText value="#{p.prodotto.nome}"/>
                                </p:column>

                                <p:column headerText="#{msg.quantitaTable}" >

                                    <h:outputText value="#{p.quantità}"/>
                                </p:column>
                            </p:dataTable>

                            <p:panel id="dettaglioSpedizione" header="#{msg.spedizioneTable}">

                                <h:panelGrid columns="1" style="border: hidden; text-align: center">

                                    <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>
                                    <h:outputText value="#{o.cliente.via}"/>
                                    <h:outputText value="#{o.cliente.cap} #{o.cliente.comune.provincia.abbreviazione} #{o.cliente.comune.nome}"/>
                                </h:panelGrid>
                            </p:panel>
                        </p:panelGrid>

                        <p:commandButton value="#{msg.confermaOrdineButton}" actionListener="#{gestioneNegozio.confermaOrdine(o)}" update="ordiniTabella"/>
                    </p:rowExpansion>
                </p:dataTable>
            </h:form>
        </h:panelGrid>
    </ui:define>

    <ui:define name="spese">

        <h:panelGrid columns="2">

            #{gestioneNegozio.ottieniSpese()}

            <h:form>

                <h:outputText value="#{msg.speseDiSpedizione}" style="margin-right: 10px"/>
                <p:inplace>
                    <p:spinner id="spinnerPrezzo" value="#{gestioneNegozio.spese}" converterMessage="#{msg.prezzoErrorM}"  stepFactor="0.5"/>
                </p:inplace>
            </h:form>
        </h:panelGrid>
    </ui:define>
</ui:composition>

